package com.eastfair.config.controller.entitycontroller;

import com.eastfair.config.entity.ThemeColor;
import com.eastfair.config.service.entityservice.ThemeColorService;
import com.eastfair.core.base.R;
import com.eastfair.projectcore.vo.ConfigAttributeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 主题色控制类
 * <p>
 * Date:2021/8/7
 * Time:15:37
 *
 * @author zjn
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/themeColor")
@Api(value = "主题色控制类", tags = "主题色控制类")
public class ThemeColorController {

    @Autowired
    private ThemeColorService ThemeColorService;

    /**
     * 获取主题色属性信息
     *
     * @return
     */
    @GetMapping("/getAttributes")
    @ApiOperation(value = "获取主题色属性信息", notes = "获取主题色属性信息")
    public R<List<ConfigAttributeVO>> getThemeColorAttributes() {
        return R.success(ThemeColorService.getAttributes());
    }

    /**
     * 获取主题色列表
     *
     * @param themeColor 主题色列表过滤条件
     * @return
     */
    @PostMapping("/getList")
    @ApiOperation(value = "获取主题色列表", notes = "获取主题色列表")
    public R<List<ThemeColor>> getList(@RequestBody(required = false) ThemeColor themeColor) {
        return R.success(ThemeColorService.getList(themeColor));
    }

    /**
     * 获取主题色
     *
     * @param flagId 标识id
     * @return
     */
    @GetMapping("/get/{flagId}")
    @ApiOperation(value = "获取主题色", notes = "获取主题色")
    public R<ThemeColor> getThemeColor(@PathVariable("flagId") Long flagId) {
        return ThemeColorService.get(flagId);
    }

    /**
     * 根据条件获取单个主题色（默认查询启用状态）
     * 必填参数：
     * terminalType 平台
     * moduleType 所属模块
     * 选填参数：
     * isEnable 是否启用
     *
     * @param themeColor 主题色过滤条件
     * @return 主题色实体
     */
    @PostMapping("/getByEntity")
    @ApiOperation(value = "根据条件获取单个主题色", notes = "根据条件获取单个主题色")
    public R<ThemeColor> getByEntity(@RequestBody @Validated({ThemeColor.VerifyGetByEntity.class}) ThemeColor themeColor) {
        return ThemeColorService.getByEntity(themeColor);
    }

    /**
     * 新增主题色
     *
     * @param themeColor 主题色实体
     * @return 是否成功
     */
    @PostMapping("/saveEntity")
    @ApiOperation(value = "新增主题色", notes = "新增主题色")
    public R<Boolean> saveEntity(@RequestBody ThemeColor themeColor) {
        return ThemeColorService.saveEntity(themeColor);
    }

    /**
     * 删除主题色
     *
     * @param flagId 主题色标识id
     * @return 是否成功
     */
    @DeleteMapping("/{flagId}")
    @ApiOperation(value = "删除主题色", notes = "删除主题色")
    public R<Boolean> deleteEntity(@PathVariable("flagId") Long flagId) {
        return ThemeColorService.deleteEntity(flagId);
    }

    /**
     * 修改主题色信息
     *
     * @param themeColor 主题色信息
     * @return 是否成功
     */
    @PutMapping("/updateEntity")
    @ApiOperation(value = "修改主题色信息", notes = "修改主题色信息")
    public R<Boolean> updateEntity(@RequestBody ThemeColor themeColor) {
        return ThemeColorService.updateEntity(themeColor);
    }

}
